<%-- 
    Document   : index
    Created on : Nov 11, 2012, 4:22:05 PM
    Author     : KaiLee
--%>


<%@page import="bean_Admin_Product.connectSQL"%>
<%@page import="bean_Admin_Product.ProductBean"%>
<%@page import="java.util.ArrayList"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>


<%
    ArrayList<ProductBean> list = (ArrayList<ProductBean>) session.getValue("list");
    String msg = request.getParameter("msg");
    ProductBean sanpham = (ProductBean) session.getValue("sanpham");
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Baby's day shop</title>
        
        <meta name="keywords" content="baby's day shop" />
        <meta name="description" content="Baby's day" />
        <link href="css/index_style.css" rel="stylesheet" type="text/css" />


    </head>

    <body>
        <%
            if (session.getValue("username") == null) {
                response.sendRedirect("admin.jsp");
            }
        %>
         <div id="baby_wrapper_outter">
            <div id="baby_wrapper_inner">
                <jsp:include page="headerAdmin.jsp"/>
                <div id="baby_content_wrapper">

                    <jsp:include page="menuLeftAdmin.jsp"/>

                    <div id="baby_content">

                        <div id="them">
                            <form action="Update" name="themsanpham" onSubmit="return checkInput();">
                                <table>
                                    <tr><h2> Thông tin chi tiết sản phẩm </h2></tr>
                                    <tr>
                                        <td width="30%">Mã sản phẩm</td>
                                        <td><input type="text" name="ma" maxlength="70" value="<%=sanpham.getId()%>" /></td>
                                    </tr>
                                    <tr >
                                        <td width="30%"> Tên sản phẩm: </td>
                                        <td> <input type="text" name="tenSanPham" size="30" maxlength="70" value="<%=sanpham.getName()%>"/> ${requestScope.errTen }</td>
                                    </tr>
                                    <tr >
                                        <td width="30%">Loại: </td>
                                        <td > <select width="50" name="Loai">
                                                <option> San pham be trai </option>
                                                <option> San pham be gai </option>
                                            </select> </td>

                                    </tr>
                                    <tr>
                                        <td width="30%">Nhà cung cấp:</td>
                                        <td>
                                            <select width="30" name="nhacungcap">
                                                <option>blue sky</option>
                                                <option>good day</option>
                                                <option>kids</option>
                                                <option>for u</option>
                                                <option>baby'day</option>

                                            </select>

                                        </td>
                                    </tr>

                                    <tr>
                                        <td width="30%">Giá:</td>
                                        <td><input type="text" name="gia" maxlength="70"value="<%=sanpham.getPrice()%>"/> ${requestScope.errGia }</td>
                                    </tr>

                                    <tr>
                                        <td width="30%">Ảnh:</td>
                                        <td><input type="file" name="duongdan" maxlength="70"value="<%=sanpham.getImage()%>"/> ${requestScope.errAnh }</td>
                                    </tr>

                                    <tr>
                                        <td width="30%">Số lượng:</td>
                                        <td><input type="text" name="soluong"maxlength="70" value="<%=sanpham.getQuantity()%>"/></td>
                                    </tr>

                                    <tr>
                                        <td width="30%">Mô tả</td>
                                        <td> <input type="text"  name="mota" maxlength="70"value="<%=sanpham.getDetail()%>"  cols="40" rows="5" /> ${requestScope.errMota }</textarea> </td>
                                    </tr>

                                    <tr>
                                        <td width="30%">Trạng thái </td>
                                        <td> <input type="text" name="trangthai" maxlength="70"value="<%=sanpham.getState()%>"/></td>
                                    </tr>

                                    <tr>
                                        <td><input type="submit" name="xacnhan" value="Update" /></td>
                                        <td><input type="reset" name="huybo" value="Huỷ bỏ"/></td>
                                    </tr>
                                </table>
                            </form>
                        </div>

                        <%    if ((msg != null) && (msg.equals("1"))) {%>   

                        <SCRIPT language=JavaScript> 
                            alert ("Xoá thành công!");       
                        </SCRIPT> 

                        <p align="center"></p>  
                        <%}
                        if ((msg != null) && (msg.equals("0"))) {%>   

                        <SCRIPT language=JavaScript> 
                            alert ("Dữ liệu không thể xoá!");       
                        </SCRIPT> 

                        <p align="center"></p>  
                        <%}
                        if ((msg != null) && (msg.equals("2"))) {%>   

                        <SCRIPT language=JavaScript> 
                            alert ("Trung ma san pham!");       
                        </SCRIPT> 

                        <p align="center"></p>  
                        <%}%>            


                    </div>
                        
                        <form action="DeleteServlet">

                        <table width="100%" border="1" align="center">

                            
                            <tr>
                                <div>
                                <td width="5%"><h3>Mã sản phẩm</h3></td>
                                <td width="10%"><h3>Tên sản phẩm</h3></td>
                                <td width="10%"><h3>Loại<h3></td>
                                <td width="10%"><h3>Nhà cung cấp<h3></td>
                                <td width="10%"><h3>Giá<h3></td>
                                <td width="10%"><h3>Ảnh<h3></td>
                                <td width="10%"><h3>Mô tả<h3></td>
                                <td width="5%"><h3> Số lượng <h3></td>
                                <td width="8%"><h3>Tình trạng<h3></td>
                                <td width="5%"><h3> Chọn xoá nhiều<h3></td>
                                <td width="10%"><h3> Chọn xoá một<h3> </td>
                                <td width="10%"><h3> Sửa thông tin <h3></td>
                                </div>





                                <%



                                    int fID;
                                    String fname = null;
                                    String ftype = null;
                                    String fprovider = null;
                                    int fprice = 0;
                                    String fimage = null;
                                    String fdetail = null;
                                    int fquantity;
                                    String fstate = null;

                                    int i = 0;
                                    while (i < list.size()) {
                                        fID = list.get(i).getId();
                                        fname = list.get(i).getName();
                                        ftype = list.get(i).getType();
                                        fprovider = list.get(i).getProvider();
                                        fprice = list.get(i).getPrice();
                                        fimage = list.get(i).getImage();
                                        fdetail = list.get(i).getDetail();
                                        fquantity = list.get(i).getQuantity();
                                        fstate = list.get(i).getState();


                                %>

                                <tr style="color: #000; font-size: 17px;">
                                    <td><%= fID%></td>
                                    <td><%= fname%></td>
                                    <td><%= ftype%></td>
                                    <td><%= fprovider%></td>
                                    <td><%= fprice%></td>
                                    <td><%= fimage%></td>
                                    <td><%= fdetail%></td>
                                    <td><%= fquantity%></td>
                                    <td><%= fstate%></td>

                                    <td width="3%">

                                        <label>
                                            <!-- Tao 1 checkbox de luu gia tri cua Product id trong form  --> 
                                            <input type="checkbox" name="chon" value="<%=fID%>">
                                        </label>
                                    </td>
                                    <td width="9%"><a href="Delete?fID=<%=fID%>" >Delete One </a></td>
                                    <td width="8%"><a href="UpdateServlet?fID=<%=fID%>">Update</a></td>
                                </tr>
                                <%
                                        i++;
                                    }
                                %>
                            </tr>
                        </table>
                            
                        <%
                        connectSQL conn = new connectSQL();
                        int trang = conn.soTrang(3);
                        int j = 1;
                        while (j <= trang) {

                        %>
                         <a href="PhanTrangServlet?trang=<%=j%>"><%=j%></a>
                        <%
                            j++;
                        }
                           %>
                             <input type="submit" value="Xoá nhiều"/>
                    </form>
                    <div class="cleaner"></div>


                </div> 

            </div> <!-- end of templatemo_wrapper_inner -->

        </div> <!-- end of templatemo_wrapper_outter -->
        <jsp:include page="footerAdmin.jsp"/>

    </body>
</html>

<SCRIPT LANGUAGE="JavaScript">
    <!--Ham xu ly khi ta tich chuot vao Delete -->
    function DeleteLinks()
    {
                
        if (confirm("Are you sure to delete?") == true)
        {
            //document.frmDelete.action = "DeleteServlet";
            document.frmDelete.submit();
            return true;
        }
        return false;
    }
</SCRIPT>


<SCRIPT language=JavaScript>
    function checkInput()
    {
        if (document.themsanpham.tenSanPham.value=="" || document.themsanpham.gia.value=="" || document.themsanpham.duongdan.value=="" || document.themsanpham.soluong.value=="" || document.themsanpham.soluong.value=="" || document.themsanpham.mota.value=="" || document.themsanpham.trangthai.value=="")
        {
            alert("Bạn hãy nhập đủ thông tin sửa");   
            return false;
        }
       
        return true;
    }              
</script>
